package com.kiki.history.mapper;

import java.util.List;
import com.kiki.history.domain.ListeningHistory;
import com.kiki.song.domain.main.SongCount;
import org.apache.ibatis.annotations.Select;

/**
 * 收听历史Mapper接口
 * 
 * @author 林志毅
 * @date 2025-01-09
 */
public interface ListeningHistoryMapper 
{
    /**
     * 查询收听历史
     * 
     * @param historyId 收听历史主键
     * @return 收听历史
     */
    public ListeningHistory selectListeningHistoryByHistoryId(Long historyId);

    /**
     * 查询收听历史列表
     * 
     * @param listeningHistory 收听历史
     * @return 收听历史集合
     */
    public List<ListeningHistory> selectListeningHistoryList(ListeningHistory listeningHistory);

    /**
     * 新增收听历史
     * 
     * @param listeningHistory 收听历史
     * @return 结果
     */
    public int insertListeningHistory(ListeningHistory listeningHistory);

    /**
     * 修改收听历史
     * 
     * @param listeningHistory 收听历史
     * @return 结果
     */
    public int updateListeningHistory(ListeningHistory listeningHistory);

    /**
     * 删除收听历史
     * 
     * @param historyId 收听历史主键
     * @return 结果
     */
    public int deleteListeningHistoryByHistoryId(Long historyId);

    /**
     * 批量删除收听历史
     * 
     * @param historyIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteListeningHistoryByHistoryIds(Long[] historyIds);

    @Select("select song_id from listening_history where user_id = #{userId}")
    List<Long> listHistoryByUserId(Long userId);

    @Select("select song_id from listening_history")
    List<Long> listSongIdList();

    @Select("select count(1) from listening_history where song_id = #{songId}")
    Long getPlayCount(Long songId);

    @Select("select song_id from listening_history where user_id=#{uid} group by song_id")
    List<Long> getHistorySongIdsByUserId(Long uid);

    @Select("select count(1) from listening_history where user_id=#{uid}")
    int getListByUserId(int userid);

    @Select("select user_id from listening_history group by user_id")
    List<Long> getAllUserId();

    @Select("SELECT COUNT(DISTINCT song_id) AS distinct_song_id_count\n" +
            "FROM listening_history")
    int getNumItems();

    @Select("select song_id,count(1) AS count from listening_history where user_id =#{userId1} group by song_id")
    List<SongCount> getSongCountsByUserId(Long userId1);

    @Select("select song_id from listening_history group by song_id;")
    int[] getSongIdArray();

    @Select("select song_id from listening_history where user_id=#{userId}")
    List<Long> getSearchHistoryByUserId(int userId);
}
